package com.ruoyi.charge.event;

import com.ruoyi.charge.manager.ChargingPileManager;
import com.ruoyi.charge.model.ChargingPile;
import com.ruoyi.charge.protocol.IClientService;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.NetSocket;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.EventListener;
import org.noear.solon.scheduling.annotation.Async;

/**
 * 监听器 充电结束监听
 */
@Component
public class HelloEventListener implements EventListener<JsonObject> {
    @Inject
    private IClientService clientService;
    @Inject
    private ChargingPileManager chargingPileManager;

    @Override
    @Async
    public void onEvent(JsonObject event) {
        String sn = event.getString("sn");
        String gunNo = event.getString("gunNo");
        ChargingPile chargingPile = chargingPileManager.getChargingPile(sn);
        NetSocket socket = chargingPile.getSocket();
        clientService.chargeEnd(socket, sn, gunNo);
    }
}
